package com.itheima.demo;

import com.itheima.domain.Orders;
import com.itheima.mapper.OrdersMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.util.List;

public class Demo02 {
    public static void main(String[] args) throws Exception {
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("sql.xml"));
        SqlSession session = factory.openSession();

        OrdersMapper mapper = session.getMapper(OrdersMapper.class);
        List<Orders> list = mapper.findAll();
        for (Orders o : list) {
            System.out.println("订单编号:"+o.getNumber());
            System.out.println("用户名称:"+o.getUser().getUsername());
        }
        session.close();
    }
}
